package com.atguigu.boot.admin.interceptor;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author : leimingchao
 * @date Date : 2021年11月21日 19:07
 */
// @Component
public class RedisUrlCountInterceptor implements HandlerInterceptor {

    // @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        String uri = request.getRequestURI();
        //默认每次访问当前uri就会计数加1
        stringRedisTemplate.opsForValue().increment(uri);
        return true;
    }
}
